var link;
<% if @action_link&.position %>
link = ActiveScaffold.find_action_link('<%= element_form_id(action: action_name) %>');
<% end %>
<% if successful? %>
  <% if @record %>
    <%= render 'update_messages' %>
    <% row = escape_javascript(render(list_record_view, record: @record)) -%>
    <% if @action_link&.position %>
if (link) link.close('<%= row %>');
    <% else %>
      ActiveScaffold.update_row('<%= element_row_id(action: :list, id: @record.id) %>', '<%= row %>');
      ActiveScaffold.scroll_to('<%= element_row_id(action: :list, id: @record.id) %>', true);
    <% end %>
    <%= render 'update_calculations' %>
  <% else %>
    <% if @action_link&.position %>
if (link) link.close();
    <% end %>
    <%= render 'refresh_list', no_history: true %>
  <% end %>
<% else %>
  <%
    if @record&.errors.present?
      object_name = "#{@record.class.model_name.human.downcase}#{@record.new_record? ? '' : ": #{@record.to_label}"}"
      flash[:error] = active_scaffold_error_messages_for(@record, object_name: object_name, header_message: '', message: object_name, container_tag: nil, list_type: :br)
    end
  %>
  <% messages = escape_javascript(render('messages')) %>
  <% if @action_link&.position %>
if (link) {
  link.update_flash_messages('<%= messages %>');
  ActiveScaffold.enable_form(link.adapter.find('form'));
}
  <% else %>
  ActiveScaffold.replace_html('<%= active_scaffold_messages_id %>', '<%= messages %>');
  ActiveScaffold.scroll_to('<%= active_scaffold_messages_id %>', true);
  <% end %>
<% end %>
